//
//  225. 用队列实现栈.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/9/12.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation
class MyStack {
    var queue1: [Int] = [] // 始终是空的
    var queue2: [Int] = [] // 始终是有值的
    /** Initialize your data structure here. */
    init() {
        
    }
    
    /** Push element x onto stack. */
    func push(_ x: Int) {
        queue1.append(x)
        while !queue2.isEmpty {
            let first = queue2.removeFirst()
            queue1.append(first)
        }
        let tmp = queue2
        queue2 = queue1
        queue1 = tmp
    }
    
    /** Removes the element on top of the stack and returns that element. */
    func pop() -> Int {
       return queue2.removeFirst()
    }
    
    /** Get the top element. */
    func top() -> Int {
        return queue2.first!
    }
    
    /** Returns whether the stack is empty. */
    func empty() -> Bool {
        return queue2.isEmpty
    }
}
class Solution225 {
    // 用队列实现栈
    static func test() {
        
    }
}
